package com.tianhui.consignortwofei.mvp.ui.activity.audit.vehicle;

import android.os.Bundle;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.entity.PictureInfo;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.mvp.model.enty.SelectPhotoInfo;
import com.tianhui.consignortwofei.mvp.model.enty.VehicleInfo;
import com.tianhui.consignortwofei.mvp.model.enty.authLicense.VehicleLicenseInfo;
import com.tianhui.consignortwofei.other.auth.PictureContext;
import com.tianhui.consignortwofei.other.auth.inte.SelectPhotoCallback;
import com.tianhui.consignortwofei.other.auth.stragety.VehicleBack2Strategy;

import butterknife.OnClick;

public class VehicleBack2AuditActivity extends BaseVehicleAuditActivity {


//    @BindView(R.id.activity_vehicle_back2_audit_endDateClickItemView)
//    ClickItemView mEndDateClickItemView;

//    private TimePickerView mEndDatePickerView;
    private String mBackImageId;

    @Override
    public int getLayoutId() {
        return R.layout.activity_vehicle_back2_audit;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @Override
    public void changePictureSuccess(PictureInfo pictureInfo) {
        mBackImageId = pictureInfo.id;
    }

    @Override
    public void showVehicleInfo(VehicleInfo info) {
//        mEndDateClickItemView.setContent(info.effectivedate);
        loadPicture(info.imganchorcompayimage);
        mBackImageId = info.anchorcompayimage;

    }

    @Override
    public String getToolbarSubtitle() {
        return "跳过";
    }

    @Override
    public void onSubtitleClick() {
        openActivityForResult(VehicleTowedFrontAuditActivity.class, getIntent().getExtras());
    }

    @Override
    public VehicleInfo getSaveInfo() {
//        String endDate = mEndDateClickItemView.getContent();
//        if (TextUtils.isEmpty(endDate)) {
//            showToast("请选择检验有效期");
//            return null;
//        }
//        mVehicleInfo.effectivedate = endDate;
        mVehicleInfo.anchorcompayimage = mBackImageId;
        return mVehicleInfo;
    }

    @Override
    public void nextAudit() {
        VehicleInfo vehicleInfo = getSaveInfo();
        if (vehicleInfo != null) {
            Bundle bundle = new Bundle();
            bundle.putParcelable(KeyValue.KEY_VEHICLE_INFO, vehicleInfo);
            bundle.putInt(KeyValue.KEY_OPERATE,getIntent().getExtras().getInt(KeyValue.KEY_OPERATE));
            openActivityForResult(VehicleTowedFrontAuditActivity.class, bundle);
        }
    }

    //检验有效期
    @OnClick(R.id.activity_vehicle_back2_audit_endDateClickItemView)
    public void selectEndDate() {
        hideKeyboard();
//        if (mEndDatePickerView == null) {
//            mEndDatePickerView = new TimePickerBuilder(this, new OnTimeSelectListener() {
//                @Override
//                public void onTimeSelected(Date date, View v) {
//                    String string = DateUtil.getStandardTime(date.getTime(), "yyyy-MM-dd");
//                    mEndDateClickItemView.setContent(string);
//                }
//            })
//                    .setTitleText("请选择日期")
//                    .build();
//        }
//        mEndDatePickerView.show();
    }


    @OnClick(R.id.layout_audit_picture_editImageView)
    public void changePicture() {
        VehicleBack2Strategy vehicleBackStrategy = (VehicleBack2Strategy) pictureStrategyFactory.createStrategy(VehicleBack2Strategy.class);
        pictureContext = new PictureContext(vehicleBackStrategy);
        pictureContext.selectPhoto(getContext(), new SelectPhotoCallback<VehicleLicenseInfo>() {
            @Override
            public void selectPhotoSuccess(SelectPhotoInfo<VehicleLicenseInfo> resultInfo) {
                mBackImageId = resultInfo.pictureId;
                loadPicture(resultInfo.realFileName);
                processVehicleBackResult(resultInfo.resultInfo);
            }

            @Override
            public void selectPhotoFailed() {

            }
        });
    }

    private void processVehicleBackResult(VehicleLicenseInfo resultInfo) {
        if (resultInfo == null) return;
//        mEndDateClickItemView.setContent(resultInfo.indate);
    }
}
